﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RooHui.OA.Biz;
using RooHui.Tool;

namespace RooHui.OA.Web.Controllers
{
    public class ProjectAuditController : Controller
    {
        //
        // GET: /ProjectAudit/

        public ActionResult Index()
        {
            return View();
        }

       

        public ActionResult ProjectAudit(int projectID)
        {
            var project = ProjectAuditBiz.GetProjectByIDForAudit(projectID);
            var processDoing = ProcessDoingBiz.GetProcessDoingByProjectID(projectID);
            var processStepList = ProcessStepDoingBiz.GetProcessStepDoingList(projectID, processDoing.ProcessID);
            var processDoingHistoryList= ProcessDoingHistoryBiz.GetProcessDoingHistoryList(projectID);
            var repaymentPlanList=RepaymentPlanBiz.BuildRepaymentPlan(projectID);
            ViewBag.processDoing = processDoing;
            ViewBag.project = project;
            ViewBag.processStepList = processStepList;
            ViewBag.processDoingHistoryList = processDoingHistoryList;
            ViewBag.repaymentPlanList = repaymentPlanList;
            return View();
        }

        [HttpPost]
        public ActionResult GetProjectListForAudit(int page, int pageSize, int guaranteeCompanyID=-1, string key="")
        {
            int count = 0;
            var projectList = ProjectAuditBiz.GetProjectListForAudit(page, pageSize, guaranteeCompanyID, key,System.Web.HttpContext.Current.User.Identity.Name, ref count);

            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("Rows", projectList);
            dic.Add("Total", count);
            return Content(dic.ToJson());
        }
        [HttpPost]
        public ActionResult ProjectAuditDo(int projectID,int processStepDoingID,string doContent="")
        {

            if (ProcessDoingBiz.ProcessDone(projectID, processStepDoingID, doContent, System.Web.HttpContext.Current.User.Identity.Name))
            {
                return Content("1");
            }
            return Content("0");
        }

    }
}
